package com.huawei.ohos.myapplication;

import com.huawei.ohos.myapplication.utils.CommonData;
import ohos.aafwk.content.Operation;
import ohos.ace.ability.AceAbility;
import ohos.aafwk.content.Intent;
import ohos.bundle.AbilityInfo;
import ohos.bundle.IBundleManager;
import ohos.data.distributed.common.KvManagerConfig;
import ohos.data.distributed.common.KvManagerFactory;
import ohos.data.distributed.common.KvStoreException;
import ohos.distributedschedule.interwork.DeviceInfo;
import ohos.distributedschedule.interwork.DeviceManager;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
import ohos.rpc.*;
import ohos.utils.zson.ZSONObject;

import java.util.*;

import static ohos.security.SystemPermission.DISTRIBUTED_DATASYNC;

public class MainAbility extends AceAbility {
    private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP, 0, "MAIN_JKY");

    @Override
    public void onStart(Intent intent) {
        HiLog.info(LABEL, "MainAbility::onStart");
        super.onStart(intent);
        grantPermission();
    }

    //申请权限，否则无法调用分布式能力
    void grantPermission() {
        if (verifySelfPermission(DISTRIBUTED_DATASYNC) != IBundleManager.PERMISSION_GRANTED) {
            if (canRequestPermission(DISTRIBUTED_DATASYNC)) {
                requestPermissionsFromUser(new String[] {DISTRIBUTED_DATASYNC}, 0);
            }
        }
    }

    @Override
    public void onStop() {
        super.onStop();
    }

    @Override
    protected void onCommand(Intent intent, boolean restart, int startId) {
        HiLog.info(LABEL, "MainAbility::onCommand");
        super.onCommand(intent, restart, startId);
    }
}
